-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
test(man): fix skip failure of test_10
#529
Conversation
The failure of The previous code using [Bug fix] Correctly restore
|
test_10
test_10
… /dev/null Users often set `BASH_COMPLETION_USER_FILE=/dev/null' to explicitly express that there is no user configuration file. However, in broken systems, /dev/null may be a regular file that contains random outputs from arbitary commands whose outputs are discarded. We shall explicitly confirm that the path is not `/dev/null' before sourcing because we do not want to source this unexpected `/dev/null' file. In fact, this caused a problem in the CI testing on GitHub [1] where the command history is output to `HISTFILE=/dev/null'. Here, `/dev/null' gets the history entry `source bash_completion' and then sourced from `bash_completion' itself, which results in an infinite source chain of `bash_completion' -> `/dev/null' -> `bash_completion' -> `/dev/null' -> ... while invoking random commands from the command history. [1] scop#529
Users often set `BASH_COMPLETION_USER_FILE=/dev/null' to explicitly express that there is no user configuration file. However, in broken systems, /dev/null may be a regular file that contains random outputs from arbitary commands whose outputs are discarded. We shall explicitly confirm that the path is not `/dev/null' before sourcing because we do not want to source this unexpected `/dev/null' file. In fact, this caused a problem in the CI testing on GitHub [1] where the command history is output to `HISTFILE=/dev/null'. Here, `/dev/null' gets the history entry `source bash_completion' and then sourced from `bash_completion' itself, which results in an infinite source chain of `bash_completion' -> `/dev/null' -> `bash_completion' -> `/dev/null' -> ... while invoking random commands from the command history. [1] scop#529
test_10
test_10
I found that
|
HISTFILE="/dev/null", # to leave user's history file alone |
the command history including the history entry "source .../bash_completion
" are saved in the file /dev/null
. Then, bash_completion
tries to source BASH_COMPLETION_USER_FILE=/dev/null
(set up in test/config/bashrc
).
bash-completion/test/config/bashrc
Line 31 in 7e0803f
export BASH_COMPLETION_USER_FILE=/dev/null |
bash-completion/bash_completion
Lines 2371 to 2374 in 7e0803f
# source user completion file | |
user_completion=${BASH_COMPLETION_USER_FILE:-~/.bash_completion} | |
[[ ${BASH_SOURCE[0]} != "$user_completion" && -r $user_completion && -f $user_completion ]] && | |
. $user_completion |
This causes an infinite source chain of bash_completion
-> File /dev/null
-> bash_completion
-> File /dev/null
-> ...
I have added fixes to this problem 492150b. I have also rebased the commits and added the corresponding description to each commit log. Now it's ready to be reviewed and merged.
Users often set `BASH_COMPLETION_USER_FILE=/dev/null' to explicitly express that there is no user configuration file. However, in broken systems, /dev/null may be a regular file that contains random outputs from arbitary commands whose outputs are discarded. We shall explicitly confirm that the path is not `/dev/null' before sourcing because we do not want to source this unexpected `/dev/null' file. In fact, this caused a problem in the CI testing on GitHub [1] where the command history is output to `HISTFILE=/dev/null'. Here, `/dev/null' gets the history entry `source bash_completion' and then sourced from `bash_completion' itself, which results in an infinite source chain of `bash_completion' -> `/dev/null' -> `bash_completion' -> `/dev/null' -> ... while invoking random commands from the command history. [1] scop#529
I had thought that the Docker image was already broken, but looking at the test log, I guess that
The error starts to happen from |
Huh, if it's something triggered by us, then that's something we need to fix. Maybe that old bash removes It would seem safer to |
Fixes the test failure of `test_10' (test_man.py). The decorator `@pytest.mark.complete(require_cmd=True)' is referenced only when the fixture `completion' is requested. Since `completion' was not requested by `test_10', `require_cmd=True' was ignored. Now `test_10' checks the command (non-)existence on its own for test skipping.
In the previous version of `bash_env_saved', `bash.cwd' was used to retrieve the current working directory of the Bash process, but it turned out that `bash.cwd' just retains the value of the startup time of the process but not the current one. Instead we shall store the real current working directory in a shell variable inside the Bash process.
`bash_env_saved' now tries to proceed the process of the restoration of the shell environment even when some of restoration operations fail in order to reduce later errors caused by incomplete restoration.
Users often set `BASH_COMPLETION_USER_FILE=/dev/null' to explicitly express that there is no user configuration file. However, in broken systems, /dev/null may be a regular file that contains random outputs from arbitary commands whose outputs are discarded. We shall explicitly confirm that the path is not `/dev/null' before sourcing because we do not want to source this unexpected `/dev/null' file. In fact, this caused a problem in the CI testing on GitHub [1] where the command history is output to `HISTFILE=/dev/null'. Here, `/dev/null' gets the history entry `source bash_completion' and then sourced from `bash_completion' itself, which results in an infinite source chain of `bash_completion' -> `/dev/null' -> `bash_completion' -> `/dev/null' -> ... while invoking random commands from the command history. [1] scop#529
I found that it was actually a bug (or a quirk) of Bash 4.3 and lower. I found the following report in bug-bash: This means that the number of commands in the history hits the limit
I have rebased the commits on the latest |
In the previous version of `bash_env_saved', when the same variables are saved or restored in the nested `with bash_env_saved()' statement, the variables are not correctly restored. It is not clear whether there are real instances of such cases in existing tests, but `bash_env_saved' shall support the nested call of `with bash_env_saved()' to avoid future troubles.
Users often set `BASH_COMPLETION_USER_FILE=/dev/null' to explicitly express that there is no user configuration file. However, in broken systems, /dev/null may be a regular file that contains random outputs from arbitary commands whose outputs are discarded. We shall explicitly confirm that the path is not `/dev/null' before sourcing because we do not want to source this unexpected `/dev/null' file. In fact, this caused a problem in the CI testing on GitHub [1] where the command history is output to `HISTFILE=/dev/null'. Here, `/dev/null' gets the history entry `source bash_completion' and then sourced from `bash_completion' itself, which results in an infinite source chain of `bash_completion' -> `/dev/null' -> `bash_completion' -> `/dev/null' -> ... while invoking random commands from the command history. [1] scop#529
f507e2a
to
ce3583f
Compare
[Problem] We have previously set HISTFILE=/dev/null to leave user's history file alone in the test, but it turned out to break the system. When the number of history entries reach HISTFILESIZE, Bash tries to replace the entity at $HISTFILE with a regular file. HISTFILE=/dev/null causes the removal of the device /dev/null and creation of a regular file at /dev/null. This Bash behavior was fixed in Bash 4.4 after the following bug-bash discussion: https://lists.gnu.org/archive/html/bug-bash/2015-01/msg00138.html [Solution] As a workaround, we prepare an empty temporary file for each test. [Remark] Another possible solution was to unset HISTFILE in test/config/bashrc. However test/config/bashrc is sourced after the first prompt is shown, i.e., after the user's history file is loaded. This doesn't necessarily cause problems, but we rather use an empty file for the history to perform tests in a unqiue condition.
@scop Thank you for the patient review on my PR and the related discussions! Can I delete these two GitHub Workflow actions, |
No problem, thank you! By all means, go and delete them, nice catch. |
Thanks! I've deleted them. |
This fixes the test failure of
test_man.py
.@pytest.mark.complete(require_cmd=True)
is referenced only when the fixturecompletion
is requested. Sincecompletion
is not requested in the new version oftest_10
,require_cmd=True
is inactive now. This PR explicitly checks the command (non-)existence to properly skip the test.